#include<bits/stdc++.h>
using namespace std;

int t;
int n, m, L, V;
int d[100005], v[100005], a[100005];
int p[100005];
int l[100005];
struct node{
    int l, r;
} s[100005];

bool cmp(node a, node b)
{
    return a.l < b.l;
}

bool find_p(int ll, int rr)
{
    int l = 1, r = m;
    while(l <= r)
    {
        int mid = (l + r) >> 1;
        if(p[mid] < ll) l = mid + 1;
        else if(p[mid] > rr) r = mid - 1;
        else return true;
    }
    return false;
}

void solve1()
{
    int cnt = 0;
    for(int i = 1; i <= n; i++)
    {
        if(v[i] > V)
            l[++cnt] = d[i];
    }
    sort(l + 1, l + cnt + 1);
    for(int i = cnt; i >= 1; i--)
        if(l[i] <= p[m])
        {
            printf("%d %d\n", i, m - 1);
            return;
        }
    printf("%d %d\n", 0, m);
}

void solve2()
{
    int cnt = 0, ans = m;
    for(int i = 1; i <= n; i++)
    {
        if(v[i] <= V && a[i] <= 0) continue;
        if(a[i] > 0
        && 2 * a[i] * (L - d[i]) + v[i] * v[i] <= V * V)
            continue;
        if(a[i] == 0)
        {
            if(p[m] >= d[i])
            {
                cnt++;
                s[cnt].l = d[i];
                s[cnt].r = L;
            }
        }
        else if(a[i] < 0)
        {
            for(int j = 1; j <= L - d[i]; j++)
            {
                if(2 * a[i] * j + v[i] * v[i] <= V * V)
                {
                    if(find_p(d[i], d[i] + j - 1))
                    {
                        cnt++;
                        s[cnt].l = d[i];
                        s[cnt].r = d[i] + j - 1;
                    }
                    break;
                }
            }
        }
        else
        {
            for(int j = 1; j <= L - d[i]; j++)
            {
                if(2 * a[i] * j + v[i] * v[i] > V * V)
                {
                    if(d[i] + j <= p[m])
                    {
                        cnt++;
                        s[cnt].l = d[i] + j;
                        s[cnt].r = L;
                    }
                    break;
                }
            }
        }
    }

    sort(s + 1, s + cnt + 1, cmp);
    int ml = s[1].l, mr = s[1].r;
    int k;
    for(k = 1; k <= m; k++)
    {
        if(p[k] >= ml) break;
        ans--;
    }
    for(int i = 2; i <= cnt; i++)
    {
        if(s[i].l > mr)
        {
            for(k = k + 1; k <= m; k++)
            {
                if(p[k] >= s[i].l) break;
                ans--;
            }
            ml = s[i].l, mr = s[i].r;
        }
        else if(s[i].r >= mr)
        {
            if(s[i].l > p[k])
            {
                if(!find_p(s[i].l, mr))
                {
                    for(k = 1; k <= m; k++)
                    {
                        if(p[k] >= s[i].l) break;
                        ans--;
                    }
                    ml = s[i].l, mr = s[i].r;
                }
                else
                {
                    ans--;
                    ml = s[i].l;
                }
            }
            else ml = s[i].l;
        }
        else
        {
            if(s[i].l > p[k])
            {
                for(k; k <= m; k++)
                {
                    if(p[k] >= s[i].l) break;
                    ans--;
                }
            }
            ml = s[i].l, mr = s[i].r;
        }
    }
    printf("%d %d\n", cnt, m - ans);
}

int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    scanf("%d", &t);
    while(t--)
    {
        bool f = 1;
        scanf("%d %d %d %d", &n, &m, &L, &V);
        for(int i = 1; i <= n; i++)
        {
            scanf("%d %d %d", &d[i], &v[i], &a[i]);
            if(a[i]) f = 0;
        }
        for(int i = 1; i <= m; i++)
            scanf("%d", &p[i]);
        if(f)
            solve1();
        else solve2();
    }
    return 0;
}
